package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageBean;
import com.zzyl.dto.ReservationQueryDto;
import com.zzyl.entity.Reservation;
import com.zzyl.mapper.ReservationMapper;
import com.zzyl.service.ReservationService;
import com.zzyl.utils.ThreadLocalUtil;
import com.zzyl.vo.ReservationVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@Transactional
public class ReservationServiceImpl implements ReservationService {

    @Autowired
    private ReservationMapper reservationMapper;

    /**
     * 分页查找预约
     */
    @Override
    public PageBean<ReservationVo> findByPage(ReservationQueryDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        Long userId = ThreadLocalUtil.get();
        dto.setUserId(userId);
        Page<Reservation> page = reservationMapper.findByPage(dto);
        return PageBean.of(page, ReservationVo.class);
    }
}

